package org.skyeye.modeling.view;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;


/**
 * 测试覆盖率视图
 * @author Louis
 *
 */
public class TestCoverageView extends ViewPart {

	public static final String ID = TestCoverageView.class.getName();
	private Composite container;
	

	public TestCoverageView() {
	}
	
	@Override
	public void createPartControl(Composite parent) {
		container = new Composite(parent, SWT.BORDER);
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
		container.setLayout(new GridLayout(1, false));
		
		Composite containerOperation = new Composite(container, SWT.BORDER);
		containerOperation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		containerOperation.setLayout(new GridLayout(3, false));
		
		Button buttonCpu = new Button(containerOperation, SWT.FLAT);
		buttonCpu.setText("Set CPU");
		buttonCpu.setLayoutData(new GridData(GridData.FILL_VERTICAL));
		buttonCpu.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				
			}
		});
		
		Button buttonSourcePath = new Button(containerOperation, SWT.FLAT);
		buttonSourcePath.setText("source directories");
		buttonSourcePath.setLayoutData(new GridData(GridData.FILL_VERTICAL));
		buttonSourcePath.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
//				DirectoryDialog dirDialog = new DirectoryDialog(Display.getDefault().getActiveShell());  
//				IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
//				String filePaht = dirDialog.open();
//				try {
//					CodeExplorerView view = (CodeExplorerView) page.showView(CodeExplorerView.ID);
//					view.getTreeViewer().setInput(new File(filePaht));
//				} catch (PartInitException e1) {
//					e1.printStackTrace();
//				}
			}
		});
		
		Button buttonGenerator = new Button(containerOperation, SWT.FLAT);
		buttonGenerator.setText("Coverage Generation");
		buttonGenerator.setLayoutData(new GridData(GridData.FILL_VERTICAL));
		buttonGenerator.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				
			}
		});
		
		
		
		Composite containerCoverageInfo = new Composite(container, SWT.BORDER);
		containerCoverageInfo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		containerCoverageInfo.setLayout(new GridLayout(1, false));
		
		Label labelCoverage = new Label(containerCoverageInfo, SWT.NONE);
		labelCoverage.setText("building...");
		
		Composite containerCodePath = new Composite(container, SWT.BORDER);
		containerCodePath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		containerCodePath.setLayout(new GridLayout(1, false));
		
		Label labelCodePath = new Label(containerCodePath, SWT.NONE);
		labelCodePath.setText("building...");
		
	}


	@Override
	public void setFocus() {
		container.setFocus();
	}
}
